<template>
  <div>
    <!--          搜索框-->
    <div style="margin: 15px 0">
      <el-input style="width: 200px" placeholder="请输入统一社会信用代码" suffix-icon="el-icon-search" v-model="abnormalids"></el-input>
      <el-input style="width: 200px" placeholder="请输入异常单位" suffix-icon="el-icon-search" class="ml-5" v-model="abnormalname"></el-input>
      <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
      <el-button type="warning" @click="reset">重置</el-button>
    </div>

    <!--    功能按键-->
    <div style="margin: 15px 0">
      <el-button type="primary" @click="handleAdd">新增<i style="padding-left: 5px" class="el-icon-circle-plus-outline"></i></el-button>
      <el-upload action="http://localhost:9090/abnormal/import" :show-file-list="false" accept=".xlsx" :on-success="handleExcelImportSuccess" style="display: inline-block">
        <el-button type="primary" style="padding-left: 5px" class="ml-5">批量导入<i style="padding-left: 5px" class="el-icon-upload2"></i></el-button>
      </el-upload>
      <el-button type="primary" @click="exp" class="ml-5">导出<i style="padding-left: 5px" class="el-icon-download"></i></el-button>
      <el-button type="primary" @click="expform" class="ml-5">生成报表<i style="padding-left: 5px" class="el-icon-tickets"></i></el-button>
    </div>

    <!--    表单-->
    <el-table :data="tableData" border stripe :header-cell-class-name="headerBg" :cell-style="rowStyle">
      <el-table-column prop="abnormalids" label="统一社会信用代码" header-align="center">
      </el-table-column>
      <el-table-column prop="abnormalname" label="异常单位" header-align="center">
      </el-table-column>
      <el-table-column prop="abnormalmakingdate" label="做出决定时间" header-align="center">
      </el-table-column>
      <el-table-column prop="abnormalremovaldate" label="做出移出决定时间" header-align="center">
      </el-table-column>
      <el-table-column label="操作" header-align="center">
        <template slot-scope="scope">
          <el-button type="primary" @click="handleShow(scope.row)">详情<i style="padding-left: 5px" class="el-icon-view"></i></el-button>
          <el-button type="warning" @click="handleEdit(scope.row)">编辑<i style="padding-left: 5px" class="el-icon-edit"></i></el-button>
          <el-popconfirm
              class="ml-5"
              confirm-button-text='好的'
              cancel-button-text='不用了'
              icon="el-icon-info"
              icon-color="red"
              title="这是一段内容确定删除吗？"
              @confirm="handleDel(scope.row.id)"
          >
            <el-button type="danger" slot="reference">删除<i style="padding-left: 5px" class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <!--          分页-->
    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

    <!--    新增表单-->
    <el-dialog title="经营异常单位信息" :visible.sync="dialogFormVisible" width="50%">
      <el-form ref="form" :model="form" label-width="160px" :inline="true">
        <el-form-item label="统一社会信用代码">
          <el-input v-model="form.abnormalids"></el-input>
        </el-form-item>
        <el-form-item label="异常单位">
          <el-input v-model="form.abnormalname"></el-input>
        </el-form-item>
        <el-form-item label="做出决定时间">
          <el-input v-model="form.abnormalmakingdate"></el-input>
        </el-form-item>
        <el-form-item label="做出移出决定时间">
          <el-input v-model="form.abnormalremovaldate"></el-input>
        </el-form-item>
        <el-form-item label="作出决定机关">
          <el-input v-model="form.abnormalmakingauthority"></el-input>
        </el-form-item>
        <el-form-item label="作出移出决定机关">
          <el-input v-model="form.abnormalremovalauthority"></el-input>
        </el-form-item>
      </el-form>

      <el-form ref="form" :model="form" label-width="160px">
        <el-form-item label="列入经营异常原因">
          <el-input type="textarea" v-model="form.abnormalmakingreason" style="width: 85%"></el-input>
        </el-form-item>
        <el-form-item label="移出经营异常原因">
          <el-input type="textarea" v-model="form.abnormalremovalreason" style="width: 85%"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="insert">确 定</el-button>
      </div>
    </el-dialog>

    <!--    编辑表单-->
    <el-dialog title="经营异常单位信息" :visible.sync="dialogFormVisible2" width="50%">
      <el-form ref="form" :model="form" label-width="160px" :inline="true">
        <el-form-item label="统一社会信用代码">
          <el-input v-model="form.abnormalids" readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="异常单位">
          <el-input v-model="form.abnormalname"></el-input>
        </el-form-item>
        <el-form-item label="做出决定时间">
          <el-input v-model="form.abnormalmakingdate"></el-input>
        </el-form-item>
        <el-form-item label="做出移出决定时间">
          <el-input v-model="form.abnormalremovaldate"></el-input>
        </el-form-item>
        <el-form-item label="作出决定机关">
          <el-input v-model="form.abnormalmakingauthority"></el-input>
        </el-form-item>
        <el-form-item label="作出移出决定机关">
          <el-input v-model="form.abnormalremovalauthority"></el-input>
        </el-form-item>
      </el-form>

      <el-form ref="form" :model="form" label-width="160px">
        <el-form-item label="列入经营异常原因">
          <el-input type="textarea" v-model="form.abnormalmakingreason" style="width: 85%"></el-input>
        </el-form-item>
        <el-form-item label="移出经营异常原因">
          <el-input type="textarea" v-model="form.abnormalremovalreason" style="width: 85%"></el-input>
        </el-form-item>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible2 = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>

    <!--    详情表单-->
    <el-dialog title="经营异常单位信息" :visible.sync="dialogFormVisible1" width="50%">
      <el-form ref="form" :model="form" label-width="160px" :inline="true">
        <el-form-item label="统一社会信用代码">
          <el-input v-model="form.abnormalids" readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="异常单位">
          <el-input v-model="form.abnormalname" readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="做出决定时间">
          <el-input v-model="form.abnormalmakingdate" readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="做出移出决定时间">
          <el-input v-model="form.abnormalremovaldate" readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="作出决定机关">
          <el-input v-model="form.abnormalmakingauthority" readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="作出移出决定机关">
          <el-input v-model="form.abnormalremovalauthority" readonly="true"></el-input>
        </el-form-item>
      </el-form>

      <el-form ref="form" :model="form" label-width="160px">
        <el-form-item label="列入经营异常原因">
          <el-input type="textarea" v-model="form.abnormalmakingreason" style="width: 85%" readonly="true"></el-input>
        </el-form-item>
        <el-form-item label="移出经营异常原因">
          <el-input type="textarea" v-model="form.abnormalremovalreason" style="width: 85%" readonly="true"></el-input>
        </el-form-item>
      </el-form>

    </el-dialog>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Abnormal",
  data() {
    return {
      tableData: [],
      total: 0,
      pageNum: 1,
      pageSize: 5,
      abnormalids: "",
      abnormalname: "",
      dialogFormVisible: false,
      dialogFormVisible1: false,
      dialogFormVisible2: false,
      form: {},
      collapseBtnClass: 'el-icon-s-fold',
      isCollapse: false,
      sideWidth: 200,
      logoTextShow: true,
      headerBg: 'headerBg'
    }
  },
  created() {
    //请求分页查询数据
    this.load()
  },
  methods: {
    load() {
      request.get("/abnormal/page",{
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          abnormalids: this.abnormalids,
          abnormalname: this.abnormalname,
        }
      }).then(res => {
        console.log(res)
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },
    save() {
      request.post("/abnormal/save", this.form).then(res => {
        if (res.data) {
          this.$message.success("修改成功")
          this.dialogFormVisible2 = false
          this.load()
        } else {
          this.$message.error("修改失败")
        }
      })
    },
    insert() {
      request.post("/abnormal/insert", this.form).then(res => {
        if (res.data) {
          this.$message.success("新增成功")
          this.dialogFormVisible = false
          this.load()
        } else {
          this.$message.error("新增失败")
        }
      })
    },
    handleAdd() {
      this.dialogFormVisible = true
      this.form = {}
    },
    handleShow(row) {
      this.form = row
      this.dialogFormVisible1 = true
    },
    handleEdit(row) {
      this.form = row
      this.dialogFormVisible2 = true
    },
    handleDel(id) {
      request.delete("/abnormal/delete/" + id).then(res => {
        if (res) {
          this.$message.success("删除成功")
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
    },
    rowStyle() {
      return "text-align:center";
    },
    handleSizeChange(pageSize) {
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    },
    exp() {
      window.open("http://localhost:9090/abnormal/export")
    },
    handleExcelImportSuccess() {
      this.$message.success("导入成功")
      this.load()
    },
    reset() {
      this.abnormalids = ""
      this.abnormalname = ""
      this.load()
    },
    expform() {
      window.open("http://localhost:9090/abnormal/downloadPdf")
    },
  }
}
</script>

<style scoped>
.headerBg{
  background-color: #eee !important;
}
</style>